#include <aura.h>

#define Dir "/tmp/TestMutextt"

EXTERN_C void AnsiToUnic(
            /* [out] */ Aura_PWChar desc,
            /* [in] */ char *src)
{
    while (*src) {
        *desc++ = (Aura_WChar)*src++;
    }
    *desc = 0;
}

Aura_Bool AuraTest_Mutex()
{
    Aura_WaitResult result;
    Aura_Handle hMutex;
    Aura_WChar wtmp[128];

    AnsiToUnic(wtmp, Dir);
    AuraMutex_Create(wtmp, AURA_TRUE, &hMutex);
    Aura_ECode ec = AuraMutex_Lock(hMutex, AURA_INFINITE, &result);
    if(AURA_FAILED(ec)){
        Aura_printf("AURA_FAILED lock.\n");
        return AURA_FALSE;
    }
    if(Aura_WaitResult_OK != result){
        Aura_printf("time out.\n");
    }
    Aura_printf("Enter the mutex\n");
    AuraThread_Sleep(1000, &result);
    Aura_printf("Leave the mutex\n");
    AuraMutex_Unlock(hMutex);

    AuraMutex_Destroy(hMutex);
    return AURA_TRUE;
}

